function downloadFile(hrefUrl, fileName) {
    let a = document.createElement('a')
    a.href = hrefUrl
    a.download = fileName // 下载后文件名
    document.body.appendChild(a)
    a.click() // 点击下载
    document.body.removeChild(a) // 下载完成移除元素
}
function dataURLToBlob(base64Str, mimeTypeStr) {
    let bstr = window.atob(base64Str); // 解码 base-64 编码的字符串，base-64 编码使用方法是 btoa()
    let length = bstr.length;
    let u8arr = new Uint8Array(length); // 创建初始化为0的，包含length个元素的无符号整型数组
    while (length--) {
        u8arr[length] = bstr.charCodeAt(length); // 返回在指定的位置的字符的 Unicode 编码
    }
    return new Blob([u8arr], { type: mimeTypeStr }); // 返回一个blob对象
}
export const downloadFileByBase64 = (base64Str, mimeTypeStr, fileName) => {
    let myBlob = dataURLToBlob(base64Str, mimeTypeStr)
    let myUrl = window.URL.createObjectURL(myBlob)
    downloadFile(myUrl, fileName)
}
// 导出csv
export function exportCsv(columns, dataList, fileName) {
    let title = columns.map(item => item.title);
    let keyArray = columns.map(item => item.key);
    let str = [];
    str.push(title.join(',') + '\n');
    for (let i = 0; i < dataList.length; i++) {
      const temp = [];
      for (let j = 0; j < keyArray.length; j++) {
        temp.push(dataList[i][keyArray[j]]);
      }
      str.push(temp.join(',') + '\n');
    }
    let uri = 'data:text/csv;charset=utf-8,\ufeff' + encodeURIComponent(str.join(''));
    let downloadLink = document.createElement('a');
    downloadLink.href = uri;
    downloadLink.download = fileName;
    document.body.appendChild(downloadLink);
    downloadLink.click();
    document.body.removeChild(downloadLink);
  }